<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加菜单</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>

<form class="layui-form" style="width: 80%;" id="menuF">
    <input type="hidden" name="parentId" th:value="${parentId}"/>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名</label>
        <div class="layui-input-block">
            <input type="text" id="title" class="layui-input"
                   lay-verify="required" placeholder="请输入菜单名" name="title" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标</label>
        <div class="layui-input-block">
            <input type="text" id="iconPicker" lay-filter="iconPicker" class="layui-input"
                   placeholder="请填写图标代码" name="icon" value="">
            <label></label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源路径</label>
        <div class="layui-input-block">
            <input type="text" name="href" class="layui-input"
                   placeholder="请输入资源路径" value="">
            <label>（<span style="color: red">*</span>例：log/logList）</label>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="sorting" class="layui-input"
                   placeholder="排序(整数)" lay-verify="require" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-block">
            <input type="text" name="perms" class="layui-input"
                   placeholder="权限标识" value="">
            <label>（例：sys:role:list）</label>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="menuForm">立即提交</button>
        </div>
    </div>
</form>
<script th:src="@{/src/layui.js}"></script>
<script>
    layui.config({
        base:'/src/app/'
    }).use(['iconPicker','jquery','form','layer'],function () {
        var iconPicker = layui.iconPicker,
            form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;
    
        iconPicker.render({
            elem:'#iconPicker',
            //数据类型：fontClass/unicode，推荐使用fontClass
            type: 'unicode',
            // 是否开启搜索：true/false
            search: true,
            page:true,
            limit:12
        })


        form.on('submit(menuForm)',function (data) {
            $.ajax({
                url:'/menu/saveMenu',
                type:'post',
                dataType:'json',
                data:data.field,
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('添加成功',{icon:1,time:1000},function () {
                            top.layer.closeAll("iframe");
                            parent.location.reload();
                        })
                    }else{
                        layer.msg('添加失败',{icon:5});
                    }
                }

            })

            return false;
        })


    })
</script>
</body>
</html>